﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.DirectX;

namespace SimulationPresenter.Presentation.Helpers
{
    internal static class SpoolHelper
    {
        public delegate TOutput StreamConverter<TStreamBase, TOutput>(TStreamBase input);

        static internal TOutput[] ToArray<TStreamBase, TOutput>(this GraphicsStream graphicsStream, StreamConverter<TStreamBase, TOutput> convert, int numberOfElements)
        {
            Array streamArrayRaw = graphicsStream.Read(typeof(TStreamBase), numberOfElements);

            var streamArrayOut = new TOutput[streamArrayRaw.Length];
            {
                int index = 0;
                foreach (TStreamBase vertex in streamArrayRaw)
                {
                    streamArrayOut[index++] = convert(vertex);
                }
            }

            return streamArrayOut;
        }

        static internal Vector3[] TransformByMatrix(this Vector3[] vectors, Matrix transformation)
        {
            var output = vectors;
            for (int i = 0; i < output.Length; i++)
            {
                output[i].TransformCoordinate(transformation);
            }

            return output;
        }
    }
}
